package br.com.wagnerpaz.javahook;

import br.com.wagnerpaz.javahook.system.SystemInfo;
import br.com.wagnerpaz.javahook.system.UnsupportedOperationalSystem;
import br.com.wagnerpaz.javahook.win32.Win32HookManager;

/**
 * <p>Contains utility methods to install/uninstall system hooks.</p>
 * 
 * @author Wagner Paz
 * @since 1.0
 */
public class HookManager
{
	/**
	 * Install a system hook that listen to keyboard input data.
	 * 
	 * @param listener The listener. Will receive every key notification.
	 * @return true case the hook was installed sucefully.
	 * @throws UnsupportedOperationalSystem Case the operational system is not supported
	 */
	public static boolean installKeyboardHook(final NativeKeyboardListener listener)
		throws UnsupportedOperationalSystem
	{
		switch( SystemInfo.getOSType() )
		{
			case WINDOWS:
				return Win32HookManager.installKeyboardHook(listener);
		}
		
		throw new IllegalStateException();
	}
	
	/**
	 * Uninstall a keyboard system hook.
	 * 
	 * @return true case the hook was uninstalled sucefully.
	 * @throws UnsupportedOperationalSystem Case the operational system is not supported
	 */
	public static boolean uninstallKeyboardHook()
		throws UnsupportedOperationalSystem
	{
		switch( SystemInfo.getOSType() )
		{
			case WINDOWS:
				return Win32HookManager.uninstallKeyboardHook();
		}
		
		throw new IllegalStateException();
	}
	
	/**
	 * Install a system hook that listen to mouse input data.
	 * 
	 * @param listener The listener. Will receive every mouse notification.
	 * @return true case the hook was installed sucefully.
	 * @throws UnsupportedOperationalSystem Case the operational system is not supported
	 */
	public static boolean installMouseHook(final NativeMouseListener listener)
		throws UnsupportedOperationalSystem
	{
		switch( SystemInfo.getOSType() )
		{
			case WINDOWS:
				return Win32HookManager.installMouseHook(listener);
		}
		
		throw new IllegalStateException();
	}
	
	/**
	 * Uninstall a mouse system hook.
	 * 
	 * @return true case the hook was uninstalled sucefully.
	 * @throws UnsupportedOperationalSystem Case the operational system is not supported
	 */
	public static boolean uninstallMouseHook()
		throws UnsupportedOperationalSystem
	{
		switch( SystemInfo.getOSType() )
		{
			case WINDOWS:
				return Win32HookManager.uninstallMouseHook();
		}
		
		throw new IllegalStateException();
	}
}